package me.eachann.sample;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import me.eachann.widget.expand.ExpandView;

import static me.eachann.widget.expand.ExpandView.State.COLLAPSED;
import static me.eachann.widget.expand.ExpandView.State.COLLAPSING;
import static me.eachann.widget.expand.ExpandView.State.EXPANDED;


public class MainActivity extends AppCompatActivity {
private ExpandView mExpandView,mHorizontalExpandView,mExpandViewV;
private LinearLayout mTextView;
private TextView mTvState;
private ImageView mIvState;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mExpandView=findViewById(R.id.expand_view);
        mExpandViewV=findViewById(R.id.expand_view_v);
        mHorizontalExpandView=findViewById(R.id.expand_view_horizontal);
        mTextView=findViewById(R.id.tv_toggle);
        mTvState=findViewById(R.id.tv_state);
        mIvState=findViewById(R.id.iv_state);
        mTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mExpandViewV.toggle();
                mExpandView.toggle();
//                mHorizontalExpandView.toggle();
            }
        });
        mExpandView.setOnExpansionUpdateListener(new ExpandView.OnExpansionUpdateListener() {
            @Override
            public void onExpansionUpdate(float expansionFraction, int state) {
                Log.e("onExpansionUpdate","expansionFraction="+expansionFraction);
                mIvState.setRotation(expansionFraction*180);
                if(state==COLLAPSED||state==COLLAPSING){
                    mTvState.setText("展开");
                }else{
                    mTvState.setText("收起");
                }
            }
        });
    }
}
